/*
 * Mytypes.h
 *
 *  Created on: Nov 5, 2013
 *      Author: BlackVolt
 */

#ifndef MYTYPES_H_
#define MYTYPES_H_
		
		#include "derivative.h"



		typedef	unsigned char 	uint8;
		typedef unsigned int	uint16;
		typedef unsigned long	uint32;
		typedef signed int		sint16;
		typedef signed long		sint32;
		 
		//*******************PORT CONFIG Defines************************
		#define 	INPUT					0
		#define 	OUTPUT 					1
		//States Defines
		#define 	True 					1
		#define 	False 					0
		
		#define FreescaleCup	False
		
		uint16 ON_OFF_FLAG;
		
		

		
		#define		PORT_A_CLK_EN			SIM_SCGC5 |=  SIM_SCGC5_PORTA_MASK;
		#define		PORT_B_CLK_EN			SIM_SCGC5 |=  SIM_SCGC5_PORTB_MASK;
		#define		PORT_C_CLK_EN			SIM_SCGC5 |=  SIM_SCGC5_PORTC_MASK;
		#define		PORT_D_CLK_EN			SIM_SCGC5 |=  SIM_SCGC5_PORTD_MASK;
		#define		PORT_E_CLK_EN			SIM_SCGC5 |=  SIM_SCGC5_PORTE_MASK;
		
		//*******************PUSH BUTTON**************************************
		#define 	PUSH_BUTT0N_0			13
		#define		PUSH_BUTT0N_1 			17
		
		#define		PUSH_BUTT0N_0_EN		((uint32)(OUTPUT<<PUSH_BUTT0N_0)) 
		#define		PUSH_BUTT0N_1_EN		((uint32)(OUTPUT<<PUSH_BUTT0N_0)) 

		
		#define		PUSH_BUTT0N_0_PRESSED	((GPIOC_PDIR&PUSH_BUTT0N_0_EN)>0)
		#define		PUSH_BUTT0N_1_PRESSED	((GPIOC_PDIR&PUSH_BUTT0N_1_EN)>0)
		
		//*********************TMP MASK	**************************************
		#define 	TPM0_CH0				1
		#define 	TPM0_CH1				2
		#define 	TPM0_CH2				3
		#define 	TPM0_CH3				4
		//**********************LED MASK *************************************
		#define 	LED1					8
		#define 	LED2					9
		#define 	LED3					10
		#define 	LED4					11
		
		#define		LED1_MASK_EN			((uint32)(OUTPUT<<LED1)) 
		#define		LED2_MASK_EN			((uint32)(OUTPUT<<LED2)) 
		#define		LED3_MASK_EN			((uint32)(OUTPUT<<LED3)) 
		#define		LED4_MASK_EN			((uint32)(OUTPUT<<LED4)) 
		 
		#define		LED1_ON					GPIOB_PSOR = LED1_MASK_EN
		#define		LED2_ON					GPIOB_PSOR = LED2_MASK_EN
		#define		LED3_ON					GPIOB_PSOR = LED3_MASK_EN 
		#define		LED4_ON					GPIOB_PSOR = LED4_MASK_EN 
		
		#define		LED1_OFF				GPIOB_PCOR = LED1_MASK_EN
		#define		LED2_OFF				GPIOB_PCOR = LED2_MASK_EN
		#define		LED3_OFF				GPIOB_PCOR = LED3_MASK_EN 
		#define		LED4_OFF				GPIOB_PCOR = LED4_MASK_EN 
		
		#define		LED1_TOG				GPIOB_PTOR = LED1_MASK_EN
		#define		LED2_TOG				GPIOB_PTOR = LED2_MASK_EN
		#define		LED3_TOG				GPIOB_PTOR = LED3_MASK_EN 
		#define		LED4_TOG				GPIOB_PTOR = LED4_MASK_EN 
			

		//************************PWM Defines*************************************
		#define		PWM_MAX_COUNT			0xFFFF;
		#define 	PWM_HALF_COUNT			0x7FFF;
		#define     PWM_10_PERCENT			0x1999;
		#define		PWM_15_PERCENT			0x2666;	
		#define		PWM_20_PERCENT			0x3333;
		#define		PWM_30_PERCENT			0x4CCC;
		#define		PWM_70_PERCENT			0xB332;
		#define		PWM_80_PERCENT			0xCCCC;
		#define		PWM_85_PERCENT			0xD998;
		#define		PWM_87_PERCENT			0xDEB7;	
		#define		PWM_88_PERCENT			0xE146;	
		#define		PWM_90_PERCENT			0xE66F;
		#define		PWM_99_PERCENT			0xFD6F;
		
		//************************SERVO Defines*************************************
		#define		PWM_20ms_PERIOD			0xEA60; 
		
		#if FreescaleCup
		//************************** Movement ************************************
		#else
		
		#define		PWM_FOWARD_STOP_LEFT	TPM0_C0V = 0;		
		#define		PWM_FOWARD_STOP_RIGHT	TPM0_C1V = 0;	
		#define		PWM_REVERSE_STOP_LEFT	TPM0_C2V = 0;	
		#define		PWM_REVERSE_STOP_RIGHT	TPM0_C3V = 0;	
		
		
		#define		PWM_FOWARD_SLOW_LEFT	TPM0_C0V = PWM_15_PERCENT;
		#define		PWM_FOWARD_SLOW_RIGHT	TPM0_C2V = PWM_15_PERCENT;
		#define		PWM_FOWARD_MID_LEFT		TPM0_C0V = PWM_30_PERCENT;
		#define		PWM_FOWARD_MID_RIGHT	TPM0_C2V = PWM_30_PERCENT;
		#define		PWM_FOWARD_HIGH_RIGHT	TPM0_C2V = PWM_HALF_COUNT;
		
		#define		PWM_REVERSE_SLOW_LEFT	TPM0_C1V = PWM_15_PERCENT;
		#define		PWM_REVERSE_SLOW_RIGHT	TPM0_C3V = PWM_15_PERCENT;
		#define		PWM_REVERSE_MID_LEFT	TPM0_C1V = PWM_30_PERCENT;
		#define		PWM_REVERSE_MID_RIGHT	TPM0_C3V = PWM_30_PERCENT;
		#define		PWM_REVERSE_HIGH_RIGHT	TPM0_C2V = PWM_HALF_COUNT;
		
		#define		PWM_FOWARD_ON_LEFT		TPM0_C1SC |=  TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK;
		#define		PWM_FOWARD_ON_RIGHT		TPM0_C3SC |=  TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK;
			
		#define		PWM_REVERSE_ON_LEFT		TPM0_C1SC |=  TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK;
		#define		PWM_REVERSE_ON_RIGHT	TPM0_C3SC |=  TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK;

		#endif
		
		//************************H-BRIDGE Defines********************************
		#define 	H_BRIDGE_MASK			(uint32_t)(1<<21)				
		#define		H_BRIDGE_EN				GPIOE_PSOR = H_BRIDGE_MASK;
		#define 	H_BRIDGE_DIS			GPIOE_PCOR = H_BRIDGE_MASK;
		#define		H_BRIDGE_TOG			GPIOE_PTOR = H_BRIDGE_MASK;
		
		//*************************  ADC   ***************************************
		#define 	ADC_CH0_SE6B			5
		#define 	ADC_CH0_SE7B			6
		
		//*************************  PIT   ***************************************
		#define 	PIT_ENABLE				PIT_TCTRL_TEN_MASK	//It must always be masked with an or |=
		#define 	PIT_DISABLE				0					//It must always be masked with an or |=
		
		//************************ CAMERA  ***************************************
		#define 	CAMERA_CLOCK			2
		#define		TRUNCATED_PIXELS		14
		//Global variables
		uint16 Frecuency_Real;
		
		//************************ SERVO MOTOR *************************************
		
		#define		SERVO_MOTOR				0 
		/*Typedefs*/
		typedef enum e_Direction{
			_Stop,
			_Foward,
			_Reverse,
			_TurnRight,
			_TurnLeft,
			_Pot_Active,
			
		}t_Direction;
		
		//************************** Intel Cup **************************************
		uint16 ADC_Test;
		uint8 Flag_Pot_Test;
		
		

		


#endif /* MYTYPES_H_ */
